package com.zzb.myshowme.model.impl;

import android.util.Log;
import android.widget.Toast;

import com.zzb.myshowme.model.SendSecurityCodeModel;
import com.zzb.myshowme.utils.HttpManager;

import org.json.JSONException;
import org.json.JSONObject;

import okhttp3.ResponseBody;
import rx.Subscriber;

/**
 * Created by Administrator on 2016/10/19.
 */
public class SendSecurityCodeModelImpl implements SendSecurityCodeModel{

    @Override
    public void isRegister(final String phone, final SendSecurityCodeModel.OnIsRegisterFinishedListener listener) {
//        HttpManager.getInstance().doHttpRequest(HttpManager.getInstance().getHttpService().isRegisterReq(phone), new Subscriber<String>() {
        HttpManager.getInstance().doHttpRequest(HttpManager.getInstance().getHttpService().testReq(), new Subscriber<String>() {
            @Override
            public void onCompleted() {
                Log.d("upload", "onCompleted down 成功======");

            }

            @Override
            public void onError(Throwable e) {
                Log.d("down", "onError 上传头像======" + e.getMessage());
                listener.onFailure("网络连接失败，请查看网络设置");
            }

            @Override
            public void onNext(String string) {
                listener.onSuccess(phone);
//                try {
//                    JSONObject object = new JSONObject(string);
//                    if (object.getString("code").equals("success")) {
//                        listener.onSuccess(phone);
//                    } else if (object.getString("code").equals("failure")) {
//                        listener.onFailure("该账号已注册");
//                    }
//                } catch (JSONException e) {
//                    e.printStackTrace();
//                    listener.onFailure(e.toString());
//                }
            }
        });
    }
}
